<?php 

  
  // This theme uses wp_nav_menu() in one location.
  register_nav_menus( array(
    'primary' => __( 'Location Navigation', 'ccr' ),
  ) );


function new_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
  



/* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= */


add_shortcode('right_column', 'right_column_shortcode');
function right_column_shortcode($atts, $content = null)
{

  global $post; 

	if($content === null) return;
	$out = '<div class="rightwrapper">';
	$out .= '<div class="rightcolumn">';
	$out .= '<div class="innertube">';
	
		
  	$out .= '<h3>Image gallery</h3>';
  
  	$images = get_children(
  		array(
  			'post_parent' => $post->ID,
  			'post_status' => 'inherit',
  			'post_type' => 'attachment',
  			'post_mime_type' => 'image',
  			'order' => 'ASC',
  			'orderby' => 'menu_order'
  			)
  	);
  
  	if($images){
  		foreach($images as $image) :
  			$meta     =wp_get_attachment_metadata($image->ID);
  			$thumb    =wp_get_attachment_thumb_url($image->ID);          
  			$fullsize =wp_get_attachment_url($image->ID);
        $large    =wp_get_attachment_image_src($image->ID, 'large');
  			
        $out .=  '<div class="thumbnails"><a rel="lightbox-set" class="" title="' . $e_title . '" href="' . $large[0] .'"><img src="' . $thumb. '" alt="" width="60" /></a></div>';						
  	  endforeach;
  	}

	$out .= '<div style="clear:both"></div>';  
	$out .= '<h3>Events, Festivals and News</h3>';  
  $out .= '<ul>'; 
  
  $news_cat = get_posts('category=1&numberposts=15');
  
  // print_r ($news_cat);
    
  foreach($news_cat as $news) :
    $out .= '<li><a href="'. get_permalink( $news->ID ) .'">' . $news->post_title . '</a><br /></li>';
  endforeach;
  
  $out .= '</ul>'; 
  				
	$out .= $content;
	$out .= '</div>';
	$out .= '</div>';
	$out .= '</div>';		
	
	$out = shortcode_unautop($out);
	$out = balanceTags($out, true);
	
	return $out;
}



add_shortcode('main_center', 'main_center_shortcode');
function main_center_shortcode($atts, $content = null)
{

  global $post;  
  
	$out .= '<div class="centercolumn">';
	$out .= do_shortcode($content);
	$out .= '</div>';
	$out .= '<div class="clear"></div>';	
	$out = shortcode_unautop($out);
	$out = balanceTags($out, true);
   
	return $out;
}


add_shortcode('general_info', 'general_info_shortcode');
function general_info_shortcode($atts, $content = null)
{

  global $post;  

  if (!in_category( '1', $post->ID )) {

  $out .= '<ul id="content_tabs">';
  $out .= ' <li id="gen_info"><a class="active" href="/general_info/">General info</a></li>';
  $out .= ' <li id="life_ledg"><a href="/life_legend_history/">Life and Legend</a></li>';
  $out .= '</ul>';
  
  }
  
	$out .= '<div class="clear"></div>';  

  
	$out .= '<div id="general_info" class="tabbed-page">';
	$out .= $content;
	$out .= '</div>';
	$out = shortcode_unautop($out);
	$out = balanceTags($out, true);
   
	return $out;
}

add_shortcode('life_legend_history', 'life_legend_history_shortcode');
function life_legend_history_shortcode($atts, $content = null)
{

  global $post;  
  
	$out .= '<div id="life_legend_history" class="tabbed-page" style="display: none;">';
	$out .= $content;
	$out .= '</div>';
	$out = shortcode_unautop($out);
	$out = balanceTags($out, true);
   
	return $out;
}

add_shortcode('title_address_video', 'title_address_video_shortcode');
function title_address_video_shortcode($atts, $content = null)
{

  global $post;  

  $out .= '<h2 id="_content" class="entry-title">' . get_the_title($post->ID) . '</h2>';
  $out .= '<p class="small_address">' . get_post_meta($post->ID, "address", true) . '</p>';	
	$out .= do_shortcode($content);
	$out = shortcode_unautop($out);
	$out = balanceTags($out, true);
  
/*
  $out .= '<ul id="content_tabs">';
  $out .= ' <li><a class="active" href="/general_info/">General info</a></li>';
  $out .= ' <li><a href="/life_legend/">Life Legend</a></li>';
  $out .= '</ul>';
*/  
  
	return $out;
}

// Column Layout Shortcode
add_shortcode('left_column', 'left_column_shortcode');
function left_column_shortcode($atts, $content = null)
{

  global $post;    
  
	$out .= '<div class="leftcolumn">';
	$out .= '<div class="innertube">';

	if (get_post_meta($post->ID, "audio_mp3", true)) {

  $mp3_filesize = filesize('/usr/local/pem/vhosts/132262/webspace/httpdocs/wp-content/uploads/audio/' . get_post_meta($post->ID, "audio_mp3", true));

  $mp3_filesize = round($mp3_filesize /= 1048576, 2). "MB";
  
  $out .= '<a class="mp3_link" href="/wp-content/uploads/audio/' . get_post_meta($post->ID, "audio_mp3", true) . '"><span>mp3 (' . $mp3_filesize . ')</span></a>';
  
  }
  
	$out .= $content;

  global $post; 
	if ($post->ID == "1") {
    $out .= '<a href="http://www.walkni.com/d/walks/398/Giants_Causeway.pdf"><img width="220" height="65" alt="" src="/wp-content/themes/ccr_alive_v1/img/trail_download_01.png" class="alignnone size-full wp-image-178"></a>';
  } 
	
	$out .= '</div>';
	$out .= '</div>';	
	
	return $out;
}

?>